/*
 * 文件名:CSemaphore.hpp
 *
 * 	 功能描述:
 *  创建日期: 2010-12-24
 *  版本Ver0.01
 *  作者: huanying2000
 *  版权:copyright 2010 by the Camellia project 
 *  free software under the terms of the LGPL 2.1
 */

#ifndef CSEMAPHORE_HPP_
#define CSEMAPHORE_HPP_

#include "Globel.hpp"

class CSemaphore
{
	public:
		CSemaphore(key_t semkey = 0x123456);
		~CSemaphore();
		void initSemaphore(void);
		void rmSemaphore(void);
		void setSemValue(int semVal);
		int getSemValue(void);
		int getSemNCnt(void);
		bool getSemStat(void);
		bool semaphoreV(int val = 1);
		bool semaphoreP(int val = 1);

	private:
		union USem
		{
			int val;
			struct semid_ds *buf;
			unsigned short *array;
			struct seminfo *__buf;
		};

		int semid;
		key_t key;
		USem usem;
};

#endif /* CSEMAPHORE_HPP_ */
